package com.song.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.song.commonutils.ResultObj;
import com.song.eduservice.entity.EduCourse;
import com.song.eduservice.entity.EduTeacher;
import com.song.eduservice.entity.vo.EduTeacherVo;
import com.song.eduservice.service.EduCourseService;
import com.song.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author song
 * @data 2020/4/6
 */
@Api(description = "前台讲师管理")
@RestController
@RequestMapping("/eduservice/teacherFront")
public class TeacherFrontController {

    @Autowired
    EduTeacherService eduTeacherService;
    @Autowired
    EduCourseService eduCourseService;

    @ApiOperation(value = "分页查询查询讲师")
    @GetMapping("getTeacherFront/{current}/{limit}")
    public ResultObj list(@PathVariable long current, @PathVariable long limit) {
        Page<EduTeacher> page = new Page<>(current, limit);
        Map<String, Object> map = eduTeacherService.getTeacherFront(page);
        return ResultObj.ok().data(map);
    }

    /**
     * 讲师详情
     *
     * @param teacherId
     * @return
     */
    @GetMapping("getTeacherInfo/{teacherId}")
    @ApiOperation(value = "讲师详情")
    public ResultObj getTeacherInfo(@PathVariable String teacherId) {
        //讲师信息
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);
        //讲师的所有课程
        QueryWrapper<EduCourse> qw=new QueryWrapper<>();
        qw.eq("teacher_id",teacherId);
        List<EduCourse> eduList = eduCourseService.list(qw);
        return ResultObj.ok().data("teacher",eduTeacher).data("courseList",eduList);
    }
}
